<template>
  <div class="home-calendar-container">
    <div style="flex:1;">
      <div class="home-calendar-content" >
        <el-date-picker
          v-model="time"
          :clearable="false"
          :editable="false"
          type="month"
          placeholder="选择月"
          format="yyyy年MM月"
          prefix-icon="el-icon-arrow-down"
          @change="dateChange"
        />
        <!-- <span style="flex:1;"/> -->
        <div class="set-today" @click="setToday">今天</div>
      </div>
      <el-calendar v-model="time" :first-day-of-week="7">
        <template
          slot="dateCell"
          slot-scope="{date, data}">
          <div :class="{'is-selected':data.isSelected,'weekEnd':isWeekEnd(date) }" class="day-item">
            <div :class="{'active':data.isSelected }" class="num">{{ Number(data.day.split('-').slice(2).join('')) }}</div>
          </div>
        </template>
      </el-calendar>
    </div>
    <div style="flex:1;" class="dataInfo-container">
      <div class="dataInfo-content">
        <div class="dataInfo-title">
          <div class="title-day">{{ time|format('DD') }}</div>
          <div class="title-week">, 星期{{ time|getWeek }}</div>
        </div>
        <div style="margin-top:22px;">
          <el-form
            label-position="left"
            label-width="100px">
            <div class="one-row">
              <el-form-item prop="userId">
                <div slot="label" class="dataInfo-form-label">
                  <img :src="orderIcon" class="icon" alt="">
                  渠道订单:
                </div>
                <el-tooltip v-if="dataInfo.orderNum || dataInfo.orderNum === 0" placement="top">
                  <div slot="content">{{ dataInfo.orderNum }}</div>
                  <div class="overflow">{{ dataInfo.orderNum | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
              <el-form-item label="含税金额:" prop="userId" label-width="65px">
                <el-tooltip v-if="dataInfo.orderAmount || dataInfo.orderAmount === 0" placement="top">
                  <div slot="content">{{ dataInfo.orderAmount }}</div>
                  <div class="overflow">{{ dataInfo.orderAmount | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
            </div>
            <div class="one-row">
              <el-form-item label="项目订单" prop="userId">
                <div slot="label" class="dataInfo-form-label">
                  <img :src="projectOrderIcon" class="icon" alt="">
                  项目订单:
                </div>
                <el-tooltip v-if="dataInfo.projectNum || dataInfo.projectNum === 0" placement="top">
                  <div slot="content">{{ dataInfo.projectNum }}</div>
                  <div class="overflow">{{ dataInfo.projectNum | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
              <el-form-item label="含税金额:" prop="userId" label-width="65px">
                <el-tooltip v-if="dataInfo.projectAmount || dataInfo.projectAmount === 0" placement="top">
                  <div slot="content">{{ dataInfo.projectAmount }}</div>
                  <div class="overflow">{{ dataInfo.projectAmount | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
            </div>
            <div class="one-row">
              <el-form-item label="客户结算" prop="userId">
                <div slot="label" class="dataInfo-form-label">
                  <img :src="clientIcon" class="icon" alt="">
                  客户结算:
                </div>
                <el-tooltip v-if="dataInfo.clientSttle || dataInfo.clientSttle === 0" placement="top">
                  <div slot="content">{{ dataInfo.clientSttle }}</div>
                  <div class="overflow">{{ dataInfo.clientSttle | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
              <el-form-item label="结算金额:" prop="userId" label-width="65px">
                <el-tooltip v-if="dataInfo.clientSttleAmount || dataInfo.clientSttleAmount === 0" placement="top">
                  <div slot="content">{{ dataInfo.clientSttleAmount }}</div>
                  <div class="overflow">{{ dataInfo.clientSttleAmount | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
            </div>
            <div class="one-row">
              <el-form-item label="供应商结算" prop="userId">
                <div slot="label" class="dataInfo-form-label">
                  <img :src="supplierIcon" class="icon" alt="">
                  供应商结算:
                </div>
                <el-tooltip v-if="dataInfo.supplierNum || dataInfo.supplierNum === 0" placement="top">
                  <div slot="content">{{ dataInfo.supplierNum }}</div>
                  <div class="overflow">{{ dataInfo.supplierNum | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
              <el-form-item label="结算金额:" prop="userId" label-width="65px">
                <el-tooltip v-if="dataInfo.supplierAmount || dataInfo.supplierAmount === 0" placement="top">
                  <div slot="content">{{ dataInfo.supplierAmount }}</div>
                  <div class="overflow">{{ dataInfo.supplierAmount | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
            </div>
            <div class="one-row">
              <el-form-item label="预约条数" prop="userId">
                <div slot="label" class="dataInfo-form-label">
                  <img :src="timeIcon" class="icon" alt="">
                  预约条数:
                </div>
                <el-tooltip v-if="dataInfo.calendarNum || dataInfo.calendarNum === 0" placement="top">
                  <div slot="content">{{ dataInfo.calendarNum }}</div>
                  <div class="overflow">{{ dataInfo.calendarNum | numberfilter }}</div>
                </el-tooltip>
                <div v-else>--</div>
              </el-form-item>
            </div>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCalendarData } from '@/api/home';
import { format } from '@/filters/date';
import { isNumber } from '@/utils/tools';
import { moneyFilter, numberTextFormat } from '@/filters/number';
import orderIcon from '@/assets/home/orderIcon.png';
import projectOrderIcon from '@/assets/home/projectOrderIcon.png';
import clientIcon from '@/assets/home/client_settle.png';
import supplierIcon from '@/assets/home/supplier_settle.png';
import timeIcon from '@/assets/home/time.png';
export default {
  filters: {
    format,
    numberfilter(val) {
      if (!isNumber(val)) {
        return val || '--';
      } else {
        return moneyFilter(numberTextFormat(val, 1), false);
      }
    },
    getWeek(val) {
      const weekDay = val.getDay();
      let res = '';
      switch (weekDay) {
        case 0:res = '日'; break;
        case 1:res = '一'; break;
        case 2:res = '二'; break;
        case 3:res = '三'; break;
        case 4:res = '四'; break;
        case 5:res = '五'; break;
        case 6:res = '六'; break;
      }
      return res;
    }
  },
  data() {
    return {
      orderIcon, projectOrderIcon, clientIcon, supplierIcon, timeIcon,
      time: new Date(new Date().setHours(0, 0, 0, 0)),
      dataInfo: {},
      selectDate: ''
    };
  },
  watch: {
    time: function(newV) {
      this.getData(newV);
    }
  },
  created() {
    this.getData(this.time);
  },
  methods: {
    getData(time) {
      let dateTime = new Date(time).setHours(0, 0, 0, 0);
      dateTime = dateTime.toString().length === 13 ? Math.floor(dateTime / 1000) : dateTime;
      getCalendarData({ dateTime }).then(res => {
        if (res.data) {
          this.dataInfo = res.data;
        }
      });
    },
    setToday() {
      this.time = new Date(new Date().setHours(0, 0, 0, 0));
    },
    dateChange(time) {},
    isWeekEnd(date) {
      const day = date.getDay();
      return day === 0 || day === 6;
    }
  }
};
</script>

<style lang="scss" scoped>
.home-calendar-container {
  background: #FFFFFF;
  box-shadow: 2px 2px 8px 0px #DDE1EA;
  overflow: hidden;
  border-radius: 4px;
  display: flex;
  .day-item {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 400;
    color: #0D1F58;
    background-color: #fff;
    .num {
      display: inline-block;
      height: 26px;
      width: 26px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 100% 100%;
      position: relative;
      box-sizing: content-box;
      &.active {
        background-color: #B5C7FF;
        color: #fff;
      }
    }
  }
  .weekEnd {
    color: #5F77C3;
  }
  &::v-deep {
    .el-calendar {
      .el-calendar__header {
        display: none;
      }
      .el-calendar__body {
        padding: 0 0px 10px 10px;
      }
      .el-calendar-day {
        height: 40px;
        padding: 0;
      }
    }
    .el-calendar-table  {
      td {
        border: none;
      }
      th {
        font-size: 12px;
        color: #999;
        line-height: 14px;
        opacity: .8;
      }
      .prev,.next {
        .day-item {
          color: #B2BBD4;
          opacity: .6;
        }
      }
      .is-today {
        .num {
          background-color: #406EFF;
          color: #fff;
          border: none;
        }
        &.is-selected {
          .num {
            background-color: #406EFF ;
            color: #fff;
            border: 3px solid #B5C7FF;
          }
        }
      }
    }
  }
  .dataInfo-container {
    .dataInfo-title {
      font-size: 20px;
      display: flex;
      align-items: flex-end;
    }
    .title-day {
      font-size: 24px;
      font-weight: 600;
      color: #333333;
      line-height: 20px;
    }
    .title-week {
      font-size: 18px;
      font-weight: 500;
      color: #333333;
      line-height: 18px;
    }
    .dataInfo-content {
      height: 100%;
      padding: 20px 20px;
    }
  }
  .one-row {
    display: flex;
    align-items: center;
    border-bottom: 1px dashed #f4F4F4;
    padding-bottom: 10px;
    margin-bottom: 10px;
    .dataInfo-form-label {
      color: #999;
      font-size: 14px;
      display: flex;
      align-items: center;
      .icon {
        width: 16px;
        height: 16px;
        margin-right: 5px;
      }
    }
    &:last-child {
      border-bottom: none;
    }
    &::v-deep {
      .el-form-item {
        width: 50%;
        margin-bottom: 0;
        padding-right: 5px;
      }
      .el-form-item__label {
        color: #999;
        font-size: 14px;
        padding-right: 0;
      }
      .el-form-item__content {
        display: flex;
      }
    }
  }
  .home-calendar-content {
    width: 100%;
    display: flex;
    align-items: center;
    padding-left: 20px;
    margin-top: 15px;
    margin-bottom: 10px;
    &::v-deep  {
      .el-date-editor {
        position: relative;
        width: 130px;
        display: flex;
        align-items: center;
        cursor: pointer;
        .el-input__inner {
          border: none;
          height: 30px;
          font-size: 18px;
          font-weight: 600;
          color: #406EFF  ;
          padding: 0;
          cursor: pointer;
        }
        .el-input__prefix {
          width: 20px;
          position: absolute;
          height: 100%;
          right: 5px;
          left: auto;
          top: 2px;
          text-align: center;
          color: #406EFF;
          display: flex;
          align-items: center;
          .el-input__icon {
             width: 20px;
             line-height: 1;
          }
        }
      }
    }
  }

  .overflow {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display:inline-block;
    font-size: 16px;
    font-weight: 600;
    color: #333333;
  }
}
.set-today {
  color:#406EFF;
  font-size:13px;
  cursor: pointer;
  margin-left: 24px;
}
</style>
